import { defineStore } from 'pinia'
import { decorationState } from './state'
import storage from '@/utils/storage'
// import type { SubmitForm, PageType, DecorationType } from '@/views/decoration/types'
export const useDecorationStore = defineStore('settingStore', {
    state: () => decorationState,
    actions: {
        SET_ISUSERCENTER(data: number) {
            this.isUsercenterCompontents = false
            this.userCenterType = ''
            this.activeTab = data
        },
        SET_LINK_FORM(data: string) {
            this.getFrom = data
        },
        SET_ACTIVE_COMINDEX(data: number) {
            this.activeComIndex = data
        },
        SET_ACTIVE_PAGE_TYPE(type: PageType) {
            this.activePageType = type
        },
        SET_ACTIVE_PAGE(page: SubmitForm) {
            this.activePage = page
        },
        SET_DEC_TYPE(type: DecorationType) {
            this.decorationType = type
            storage.set('decorationType', type, 60 * 60 * 24)
        },
    },
    getters: {
        getterDecType(): DecorationType {
            if (this.decorationType === '') {
                if (!storage.get('decorationType')) {
                    return ''
                } else {
                    return storage.get('decorationType')
                }
            } else {
                return this.decorationType
            }
        },
    },
})

/*
 * 装修类型
 */
export enum FUNCTIONTYPE {
    TABBAR,
    CLASSIFY_PAGE,
    PERSONAL_CENTER,
    PAGE,
}
export enum DECORATION_TYPE {
    WECHAT_MINI_APP,
    PC,
    OTHERS,
}
/**
 * 装修页面类型
 * @param customize 自定义页面
 * @param classification 分类
 * @param control 控件
 */
export enum PAGETYPE {
    customize,
    classification,
    control,
    userCenter,
}
export type PageType = keyof typeof PAGETYPE
export interface SubmitForm {
    id: string
    functionType: keyof typeof FUNCTIONTYPE
    properties: any
    isDef?: boolean
    pageName?: string
    platforms: DecorationType
}
export type DecorationType = keyof typeof DECORATION_TYPE | string
/**
 * 检索商品接口返回
 */
export interface ApiRetrieveComItemType {
    createTime: string
    id: string
    initSalesVolume: number
    pic: string
    platformCategoryFirstId: string
    platformCategorySecondId: string
    platformCategoryThirdId: string
    productId: string
    productName: string
    salePrices: string[]
    salesVolume: string
    shopId: string
    shopName: string
    specs: string
    status: 'SELL_ON' | 'SELL_OFF'
}
